using System.Security.Cryptography;
using System.Text;

namespace Front._1127;

public class MD5Helper
{
    // MD5加密方法 - 添加对null输入的检查
    public static string GetMD5(string input)
    {
        // 如果输入为null，返回空字符串的MD5值（或返回空字符串）
        if (input == null)
        {
            input = string.Empty;
        }
        
        using (MD5 md5 = MD5.Create())
        {
            byte[] inputBytes = Encoding.UTF8.GetBytes(input);
            byte[] hashBytes = md5.ComputeHash(inputBytes);
            
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hashBytes.Length; i++)
            {
                sb.Append(hashBytes[i].ToString("x2"));
            }
            return sb.ToString();
        }
    }
}